package com.zuthub.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zuthub.common.annotation.Log;
import com.zuthub.common.core.controller.BaseController;
import com.zuthub.common.core.domain.AjaxResult;
import com.zuthub.common.enums.BusinessType;
import com.zuthub.system.domain.SysPolicy;
import com.zuthub.system.service.ISysPolicyService;
import com.zuthub.common.utils.poi.ExcelUtil;
import com.zuthub.common.core.page.TableDataInfo;

/**
 * 政策法规Controller
 * 
 * @author zuthub
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/system/policy")
public class SysPolicyController extends BaseController
{
    @Autowired
    private ISysPolicyService sysPolicyService;

    /**
     * 查询政策法规列表
     */
    @PreAuthorize("@ss.hasPermi('system:policy:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPolicy sysPolicy)
    {
        startPage();
        List<SysPolicy> list = sysPolicyService.selectSysPolicyList(sysPolicy);
        return getDataTable(list);
    }

    @GetMapping("/tourist")
    @CrossOrigin
    public TableDataInfo listForTourist(SysPolicy sysPolicy)
    {
        startPage();
        List<SysPolicy> list = sysPolicyService.selectSysPolicyList(sysPolicy);
        return getDataTable(list);
    }

    /**
     * 导出政策法规列表
     */
    @PreAuthorize("@ss.hasPermi('system:policy:export')")
    @Log(title = "政策法规", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysPolicy sysPolicy)
    {
        List<SysPolicy> list = sysPolicyService.selectSysPolicyList(sysPolicy);
        ExcelUtil<SysPolicy> util = new ExcelUtil<SysPolicy>(SysPolicy.class);
        return util.exportExcel(list, "policy");
    }

    /**
     * 获取政策法规详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:policy:query')")
    @GetMapping(value = "/{policyId}")
    public AjaxResult getInfo(@PathVariable("policyId") Long policyId)
    {
        return AjaxResult.success(sysPolicyService.selectSysPolicyById(policyId));
    }

    /**
     * 新增政策法规
     */
    @PreAuthorize("@ss.hasPermi('system:policy:add')")
    @Log(title = "政策法规", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPolicy sysPolicy)
    {
        return toAjax(sysPolicyService.insertSysPolicy(sysPolicy));
    }

    /**
     * 修改政策法规
     */
    @PreAuthorize("@ss.hasPermi('system:policy:edit')")
    @Log(title = "政策法规", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPolicy sysPolicy)
    {
        return toAjax(sysPolicyService.updateSysPolicy(sysPolicy));
    }

    /**
     * 删除政策法规
     */
    @PreAuthorize("@ss.hasPermi('system:policy:remove')")
    @Log(title = "政策法规", businessType = BusinessType.DELETE)
	@DeleteMapping("/{policyIds}")
    public AjaxResult remove(@PathVariable Long[] policyIds)
    {
        return toAjax(sysPolicyService.deleteSysPolicyByIds(policyIds));
    }
}
